/*
 * SettingsPanel.java
 *
 * Created on October 20, 2007, 2:09 PM
 */

package ardrumo;

import java.util.Vector;

/**
 *
 * @author  mschaff
 */
public class SettingsPanel extends javax.swing.JPanel {
	Main mn;
	
	/** Creates new form SettingsPanel */
	public SettingsPanel(Main owner) {
		initComponents();
		mn = owner;
	}
	
	/** This method is called from within the constructor to
	 * initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
        // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
        private void initComponents() {
                jPanel1 = new javax.swing.JPanel();
                lblSerialInput = new javax.swing.JLabel();
                cboSerialInput = new javax.swing.JComboBox();

                setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 0, 5));
                jPanel1.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(153, 153, 153), 1, true));
                lblSerialInput.setFont(new java.awt.Font("Lucida Grande", 0, 10));
                lblSerialInput.setText("Serial Input Device");

                cboSerialInput.setFont(new java.awt.Font("Lucida Grande", 0, 10));
                cboSerialInput.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
                cboSerialInput.addItemListener(new java.awt.event.ItemListener() {
                        public void itemStateChanged(java.awt.event.ItemEvent evt) {
                                changeSerialPort(evt);
                        }
                });

                org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
                jPanel1.setLayout(jPanel1Layout);
                jPanel1Layout.setHorizontalGroup(
                        jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(jPanel1Layout.createSequentialGroup()
                                .addContainerGap()
                                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                        .add(lblSerialInput)
                                        .add(cboSerialInput, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 261, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                .addContainerGap(304, Short.MAX_VALUE))
                );
                jPanel1Layout.setVerticalGroup(
                        jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(jPanel1Layout.createSequentialGroup()
                                .addContainerGap()
                                .add(lblSerialInput)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(cboSerialInput, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addContainerGap(21, Short.MAX_VALUE))
                );

                org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
                this.setLayout(layout);
                layout.setHorizontalGroup(
                        layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                );
                layout.setVerticalGroup(
                        layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                );
        }// </editor-fold>//GEN-END:initComponents

	private void changeSerialPort(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_changeSerialPort
		
		if( cboSerialInput.getSelectedIndex() != -1) {
			String port = cboSerialInput.getSelectedItem().toString();
			mn.setSerialPort(port);
			System.out.println("Serial port changed!");
		} else {
			System.out.println("No serial port selected yet!");
		}
	}//GEN-LAST:event_changeSerialPort
	
	
        // Variables declaration - do not modify//GEN-BEGIN:variables
        private javax.swing.JComboBox cboSerialInput;
        private javax.swing.JPanel jPanel1;
        private javax.swing.JLabel lblSerialInput;
        // End of variables declaration//GEN-END:variables
	
	public void setSerialOptions(Vector<String> vp) {
		
		cboSerialInput.removeAllItems();
		
		for(int i=0; i<vp.size(); i++) {
			cboSerialInput.addItem(vp.get(i));
		}
		
		if(cboSerialInput.getItemCount() > 0) {
			cboSerialInput.setSelectedIndex(0);
		}
	}
	
	public String getSerialInput() {
		String s = null;
		
		if(cboSerialInput.getItemCount() > 0) {
			s = cboSerialInput.getSelectedItem().toString();
		}
		
		return s;
	}
}
